/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package course.services;

import course.entities.Record;
import course.entities.UserActivity;
import course.entities.UserGroup;
import course.providers.jpa.RecordProvider;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author def
 */
@ManagedBean(name = "journalBean")
@ViewScoped
public class JournalBean extends AUserService implements Serializable {

    @EJB
    private RecordProvider recordProvider;

    public JournalBean() {
    }

    private List<UserActivity> activities;

    private List<Record> recordList;

    private List<Record> filteredRecords;

    private Record selectedRecord;
    
    private long selectedImageId;

    public long getSelectedImageId() {
        return selectedImageId;
    }

    public void setSelectedImageId(long selectedImageId) {
        this.selectedImageId = selectedImageId;
    }
    
    @PostConstruct
    public void init() {
        long userId = getCurrentUser().getId();
        UserGroup group = groupProvider.findGroupByUserId(userId);
        if (group == null) {
            addInfoMessage("User has no group, access denied");
        }
        else if(group.getGroupName().equalsIgnoreCase("admin")) {
            recordList = recordProvider.findAll();
        }
        else {
            recordList = recordProvider.findRecordsByUserId(userId);
        }
    }

    public RecordProvider getRecordProvider() {
        return recordProvider;
    }

    public void setRecordProvider(RecordProvider recordProvider) {
        this.recordProvider = recordProvider;
    }

    public List<Record> getFilteredRecords() {
        return filteredRecords;
    }

    public void setFilteredRecords(List<Record> filteredRecords) {
        this.filteredRecords = filteredRecords;
    }

    public Record getSelectedRecord() {
        return selectedRecord;
    }

    public void setSelectedRecord(Record selectedRecord) {
        this.selectedRecord = selectedRecord;
    }

    public List<Record> getRecordList() {
        return recordList;
    }

    public void setRecordList(List<Record> recordList) {
        this.recordList = recordList;
    }

    public List<UserActivity> getActivities() {
        return activities;
    }

    public void setActivities(List<UserActivity> activities) {
        this.activities = activities;
    }
   
}
